<?php

namespace app\h5api\validate;

use app\common\model\User;
use think\Validate;

class Register extends Validate
{
	protected $scene = [
        'register' => [
			'telphone',
			'shopname',
			'address',
			'province_code',
			'city_code',
			'area_code',
			'street_code',
			'imagesurl',
			'idcardimg1',
			'idcardimg2',
			'licenseimg',
			'shop_manager',
			'user_pass',
			'apply_type',
			'remark',
			'lon',
			'lat',
//			'salecode',
            'is_wholesale',
		],
	];

	protected $rule =   [
		'telphone' => 'require|mobile',
		'shopname' => 'require|max:25',
		'address' => 'require',
		'province_code' => 'require|number',
		'city_code' => 'require|number',
		'area_code' => 'require|number',
		'street_code' => 'require|number',
		'imagesurl' => 'require',
		'idcardimg1' => 'require',
		'idcardimg2' => 'require',
		'licenseimg' => 'require',
        'lon' => 'require',
        'lat' => 'require',
		'shop_manager' => 'require',
		'user_pass' => 'require',
		'apply_type' => 'require|number',
//        'salecode' => 'checkSaleCode',
        'is_wholesale' => 'checkWholesale',
	];

	protected $message  =   [
		'telphone.require' => '请填写手机号码',
		'telphone.mobile' => '手机号码格式错误',
		'shopname.require' => '请填写店铺',
		'shopname.max' => '店铺名称最多不能超过25个字符',
		'address.require' => '请填写详细地址',
		'province_code.require' => '请选择省',
		'province_code.number' => '请选择省。',
		'city_code.require' => '请选择市',
		'city_code.number' => '请选择市。',
		'area_code.require' => '请选择区',
		'area_code.number' => '请选择区。',
        'lon.require' => '请填写经纬度',
        'lat.require' => '请填写经纬度',
		'street_code.number' => '请选择街道',
		'imagesurl.require' => '商铺图片',
		'idcardimg1.require' => '请上传身份证图片正面',
		'idcardimg2.require' => '请上传身份证图片反面',
		'licenseimg.require' => '请上传营业执照',
		'shop_manager.require' => '请填写店长名称',
		'user_pass.require' => '请填写账号密码',
		'apply_type.require' => '请选择店铺类型',
		'apply_type.number' => '请选择店铺类型。',
	  ];

//    protected function checkSaleCode($value)
//    {
//        if(!empty($value)){
//            $userModel = new User();
//            $user = $userModel->getOne([['salescode'=>$value]]);
//            return !empty($user)? true : '不存在该销售员';
//        }
//        return true;
//    }
    protected function checkWholesale($value)
    {
        if(!empty($value)){
            $arr = [1,2];
            return in_array($value,$arr) == true ? true : '类型错误';
        }
        return true;
    }
}
